/* ----------------------------------------------------------------------------------------------------------------
 *  Reactor
 * ----------------------------------------------------------------------------------------------------------------
 */
package pure.engine.idea 
{
	import pure.debug.Logger;

	/**
	 * 反应器
	 * [Author] - PURE
	 * 
	 * [Hint] - 反应器有一个默认队列，便于直接获取
	 * [Feature] - vars参数列表
	 *             ① delay
	 *             ② onStart
	 *             ③ onStartParams
	 *             ④ onEnd
	 *             ⑤ onEndParams
	 */
public class Reactor implements IReactor
{
	public function Reactor()
	{
		m_reactionCombos[m_soleComboName] = ReactionCombo.getInstance(this); 
	}
	
	
	/**
	 * 加入队列
	 * 
	 * [Param] - name  反应组合名字
	 */
	public function addCombo(name:String):void
	{
		if (m_reactionCombos[name])
		{
			Logger.reportError(this, 'addCombo', '重复的反应队列名字');
		}
		m_reactionCombos[name] = ReactionCombo.getInstance(this); 
	}
	
	
	/**
	 * 获取队列
	 * 
	 * [Param] - name  反应组合名字
	 */
	public function getCombo(name:String = null):IReactionCombo
	{
		return Boolean(name == null)? m_reactionCombos[m_soleComboName] : m_reactionCombos[name];
	}
	
	
	/**
	 * 用反应融合器生成反应组合
	 * 
	 * [Param] - builder  反应建造器
	 * [Param] - name     反应组合名字
	 */
	public function fuse(fusion:IReactionFusion, params:Array = null, name:String = null):IReactionCombo
	{
		var combo:IReactionCombo = getCombo(name);
		
		fusion.construct(combo, params);
		return combo;
	}
	
	
	
	/**
	 * 结束全部队列
	 */
	public function stopAll():void
	{
		for each(var C:ReactionCombo in m_reactionCombos)
		{
			C.stop();
		}
	}
	
	
	/**
	 * 消逝
	 */
	public function dispose():void
	{
		stopAll();
		for each(var C:ReactionCombo in m_reactionCombos)
		{
			C.recycle();
		}
		m_reactionCombos = null;
	}

	
	
	
	
	
	//======================
	// Member
	//======================
	
	
	protected static var m_soleComboName:String = 'soleCombo';

	protected var m_reactionCombos:Object = { };

}

}
